/** 页面加载类 ~ 首页 v1.0.0 **/
if (window !== window.top) { top.window.location.reload(); }
/** 页面加载类 layui 加载 **/
layui.use(kaValue.layuiUse, function () {
    var admin = layui.admin;
    var popup = layui.popup;
    //加载配置  yml | json | api
    admin.setConfigurationPath(kaValue.home.ConfigurationPath);
    // 渲染
    admin.render();
    // 注销
    admin.logout(function () { homePageIndex.logout(popup); });
});
/** 页面加载类 homePageIndex 加载 **/
var homePageIndex = {
    init: function () {
        //加载水印
        ka.watermark('#side');
        ka.watermark('#content');
        //加载用户信息
        homePageIndex.loading();
        //加载末端 弹窗前端源代码
        $("#footerTitleButton").click(function () {
            ka.aJumpToUrl(kaValue.home.giteeUrl, kaValue.home.giteeTitle);
        });
        //初始化 按钮
        var bindingASpanOpts = [{
            type: 1,
            id: "accountInformation",
            title: "账户资料",
            cb: function () {
                homePageIndex.accountInformation("accountInformation");
            }
        }, {
            type: 1,
            id: "updatePassWord",
            title: "修改密码",
            cb: function () {
                homePageIndex.updatePassWord("updatePassWord");
            }
        }, {
            type: 1,
            id: "personalityHomepage",
            title: "个性主页",
            cb: function () {
                homePageIndex.personalityHomepage("personalityHomepage");
            }
        }, {
            type: 1,
            id: "myTool",
            title: "我的小工具",
            cb: function () {
                homePageIndex.myTool("myTool");
            }
        }, {
            type: 1,
            id: "clearPageCache",
            title: "清理页面缓存",
            cb: function () {
                homePageIndex.clearPageCache("clearPageCache");
            }
        }, {
            type: 1,
            id: "helpDocument",
            title: "帮助文档",
            cb: function () {
                homePageIndex.helpDocument("helpDocument");
            }
        }, {
            type: 1,
            id: "KAcommunity",
            title: "KA 社区",
            cb: function () {
                homePageIndex.KAcommunity("KAcommunity");
            }
        }, {
            type: 1,
            id: "ApplicationCommunity",
            title: "应用社区",
            cb: function () {
                homePageIndex.ApplicationCommunity("ApplicationCommunity");
            }
        }, {
            type: 1,
            id: "kaApp",
            title: "手机APP",
            cb: function () {
                homePageIndex.kaApp("kaApp");
            }
        }, {
            type: 1,
            id: "pcApp",
            title: "PC端下载(EXE)",
            cb: function () {
                homePageIndex.pcApp("pcApp");
            }
        }];
        for (var i in bindingASpanOpts) {
            var opt = bindingASpanOpts[i];
            homePageIndex.bindingASpan(opt);
        }
    },
    bindingASpan: function (opt) {
        if (opt.type == 1) {
            var style = `color: #000 !important;`;
            $("#" + opt.id).attr("href", "javascript:void(0);");
            $("#" + opt.id + " span").attr("style", style);
            $("#" + opt.id + " span").html(opt.title);
            $("#" + opt.id + " span").addClass("childSpan");
            $("#" + opt.id).click(opt.cb)
        } else if (opt.type == 2) {

        }
    },
    loading: function () { //加载用户信息
        var option = kaValue.getUrl(kaValue.home.url.getInfo);
        option.success = function (re) {
            if (re.code == 200) {
                $("#txHead").html(re.user.nickName);
            }
        }
        ka.ajax(option);
    },
    accountInformation: function (divId) { //账户信息
        var businessCardArray = kaCurrUser.getBusinessCard();
        var id = businessCardArray[0];
        var html = businessCardArray[1];
        var x = ($("#" + divId).offset().top + parseInt(50)) + "px";
        var y = ($("#" + divId).offset().left - parseInt(350)) + "px";
        top.layui.layer.open({
            type: 1, // page 层类型
            area: ['267px', '400px'],
            offset: [x, y],
            shade: [0.1, '#FFF'], // 点击遮罩区域，关闭弹层
            shadeClose: true,
            title: false,
            maxmin: false, // 允许全屏最小化
            anim: 0, // 0-6 的动画形式，-1 不开启
            content: html,
            success: function () {
                var homePageIndexNCPDData = homePageIndex.getGrmpIndexNCPDData();
                $("#scrollbox_" + id).meuiTextScroll({
                    source: { "data": homePageIndexNCPDData }, //数据源
                    format: ["name", "synopsis", "createTime", "sort"],
                    // caption: body.title,
                    line: 1,
                    speed: 5000,
                    timer: 100,
                    direction: 'up',
                    pageBtn: false
                });
            }
        });
    },
    getGrmpIndexNCPDData: function () { //获取获取公示栏
        var option = kaValue.getUrl(kaValue.home.url.getNCPDData);//获取获取公示栏
        var NCPDDatas = [];
        option.data = {
            newtype: 1
        };
        option.success = function (re) {
            if (re.code == 200) {
                NCPDDatas = re.data;
            } else {
                kaMsg.error(re);
            }
        }
        ka.ajax(option);
        return NCPDDatas;
    },
    updatePassWord: function () { //修改密码
        var configure = {
            title: "修改密码",
            formDesignerId: 96,
            formdesignerFormurlId: 1,
            width: "450px",
            height: "250px",
            cbType: 1
        }
        ka.openAddAndEditViewIndex(configure);
    },
    personalityHomepage: function () { //个性主页
        var html = `
        <div style="font-size: 17px;font-weight: bold;padding-top: 10px;padding-bottom: 5px;margin-top: 30px;line-height: 1.6;width: 98%;margin: 0 auto;">主页设置</div>
        <div style="color: #989898;margin-top: 5px;font-size: 12px;line-height: 1.6;width: 98%;margin: 0 auto;">
            提供了各种各样的主页可以选择
        </div>
        <div class="layui-form" lay-filter="form-demo-skin"><div class="layui-row" style="width: 98%;margin: 0 auto;margin-top: 10px;">`;
        html = html + `
            <div class="layui-col-xs4" style="padding-top: 10px;padding-bottom: 10px;text-align: center;">
                <input type="radio" name="personalityHomepageRadio" value="1" lay-skin="none" checked>
                <div lay-radio class="lay-skin-checkcard lay-check-dot-2" style="height: 155px;">
                    <div class="lay-skin-checkcard-avatar">
                        <span class="icon iconfont icon-liulanqi-IE" style="font-size: 30px"></span>
                    </div>
                    <div class="lay-skin-checkcard-detail">
                        <div class="lay-skin-checkcard-header">默认主页</div>
                        <div class="lay-skin-checkcard-description lay-ellipsis-multi-line">
                            KA 经典的业务主页<br/>
                            1: 待办事件<br/>
                            2: 快捷入口<br/>
                            3: 常用菜单<br/>
                            4: 新闻中心<br/>
                            5: 系统版本更新公告
                        </div>
                    </div>
                </div>
            </div>`;
        var option = kaValue.getUrl("SysHomePageListAll");
            option.async = false;
            option.success = function (re) {
                var optionDatas = re.data;
                for(var i in optionDatas){
                    var optionData = optionDatas[i];
                    html = html + `
                        <div class="layui-col-xs4" style="padding-top: 10px;padding-bottom: 10px;text-align: center;">
                            <input type="radio" name="personalityHomepageRadio" value="` + optionData.id + `" lay-skin="none" ` + (optionData.status == 1?'disabled':'') + `>
                            <div lay-radio class="lay-skin-checkcard lay-check-dot-2" style="height: 155px">
                                <div class="lay-skin-checkcard-avatar">
                                    <span class="` + optionData.icon + `" style="font-size: 30px"></span>
                                </div>
                                <div class="lay-skin-checkcard-detail">
                                    <div class="lay-skin-checkcard-header">` + optionData.name + `</div>
                                    <div class="lay-skin-checkcard-description lay-ellipsis-multi-line">
                                        ` + optionData.remark + `
                                    </div>
                                </div>
                            </div>
                        </div>
                    `
                }
                
            }
            ka.ajax(option);
        html = html + `</div>`
        top.layui.layer.open({
            type: 1, // page 层类型
            area: ['50%', '50%'],
            shade: [0.6, '#FFF'], // 点击遮罩区域，关闭弹层
            shadeClose: true,
            title: false,
            maxmin: false, // 允许全屏最小化
            anim: 0, // 0-6 的动画形式，-1 不开启
            content: html,
            success: function () {
                layui.form.render(); 
            }
        });
    },
    myTool: function () { //我的小工具
        var html = `
        <div Style="padding: 30px;overflow: auto;">
            <div class="weui-grids"  >
                <a href="javascript:;" class="weui-grid js_grid"  >
                    <div class="weui-grid__icon">
                        <img src="../component/weui/images/icon_nav_button.png" alt="">
                    </div>
                    <p class="weui-grid__label">
                        工具测试
                    </p>
                </a>
                <a href="javascript:;" class="weui-grid js_grid"  >
                    <div class="weui-grid__icon">
                        <img src="../component/weui/images/icon_nav_button.png" alt="">
                    </div>
                    <p class="weui-grid__label">
                        工具测试
                    </p>
                </a>
                <a href="javascript:;" class="weui-grid js_grid"  >
                    <div class="weui-grid__icon">
                        <img src="../component/weui/images/icon_nav_button.png" alt="">
                    </div>
                    <p class="weui-grid__label">
                        工具测试
                    </p>
                </a>
                <a href="javascript:;" class="weui-grid js_grid"  >
                    <div class="weui-grid__icon">
                        <img src="../component/weui/images/icon_nav_button.png" alt="">
                    </div>
                    <p class="weui-grid__label">
                        工具测试
                    </p>
                </a>
                <a href="javascript:;" class="weui-grid js_grid"  >
                    <div class="weui-grid__icon">
                        <img src="../component/weui/images/icon_nav_button.png" alt="">
                    </div>
                    <p class="weui-grid__label">
                        工具测试
                    </p>
                </a>
                <a href="javascript:;" class="weui-grid js_grid"  >
                    <div class="weui-grid__icon">
                        <img src="../component/weui/images/icon_nav_button.png" alt="">
                    </div>
                    <p class="weui-grid__label">
                        工具测试
                    </p>
                </a>
                <a href="javascript:;" class="weui-grid js_grid"  >
                    <div class="weui-grid__icon">
                        <img src="../component/weui/images/icon_nav_button.png" alt="">
                    </div>
                    <p class="weui-grid__label">
                        工具测试
                    </p>
                </a>
                <a href="javascript:;" class="weui-grid js_grid"  >
                    <div class="weui-grid__icon">
                        <img src="../component/weui/images/icon_nav_button.png" alt="">
                    </div>
                    <p class="weui-grid__label">
                        工具测试
                    </p>
                </a>
                <a href="javascript:;" class="weui-grid js_grid"  >
                    <div class="weui-grid__icon">
                        <img src="../component/weui/images/icon_nav_button.png" alt="">
                    </div>
                    <p class="weui-grid__label">
                        工具测试
                    </p>
                </a>
                <a href="javascript:;" class="weui-grid js_grid"  >
                    <div class="weui-grid__icon">
                        <img src="../component/weui/images/icon_nav_button.png" alt="">
                    </div>
                    <p class="weui-grid__label">
                        工具测试
                    </p>
                </a>
                <a href="javascript:;" class="weui-grid js_grid"  >
                    <div class="weui-grid__icon">
                        <img src="../component/weui/images/icon_nav_button.png" alt="">
                    </div>
                    <p class="weui-grid__label">
                        工具测试
                    </p>
                </a>
                <a href="javascript:;" class="weui-grid js_grid"  >
                    <div class="weui-grid__icon">
                        <img src="../component/weui/images/icon_nav_button.png" alt="">
                    </div>
                    <p class="weui-grid__label">
                        工具测试
                    </p>
                </a>
                <a href="javascript:;" class="weui-grid js_grid"  >
                    <div class="weui-grid__icon">
                        <img src="../component/weui/images/icon_nav_button.png" alt="">
                    </div>
                    <p class="weui-grid__label">
                        工具测试
                    </p>
                </a>
                <a href="javascript:;" class="weui-grid js_grid"  >
                    <div class="weui-grid__icon">
                        <img src="../component/weui/images/icon_nav_button.png" alt="">
                    </div>
                    <p class="weui-grid__label">
                        工具测试
                    </p>
                </a>
                <a href="javascript:;" class="weui-grid js_grid"  >
                    <div class="weui-grid__icon">
                        <img src="../component/weui/images/icon_nav_button.png" alt="">
                    </div>
                    <p class="weui-grid__label">
                        工具测试
                    </p>
                </a>
                <a href="javascript:;" class="weui-grid js_grid"  >
                    <div class="weui-grid__icon">
                        <img src="../component/weui/images/icon_nav_button.png" alt="">
                    </div>
                    <p class="weui-grid__label">
                        工具测试
                    </p>
                </a>
            </div>
        </div>
        `;
        top.layui.layer.open({
            type: 1, // page 层类型
            area: ['50%', '50%'],
            shade: [0.6, '#FFF'], // 点击遮罩区域，关闭弹层
            shadeClose: true,
            title: false,
            maxmin: false, // 允许全屏最小化
            anim: 0, // 0-6 的动画形式，-1 不开启
            content: html,
            success: function () {
                layui.form.render(); 
            }
        });
    },
    clearPageCache: function (divId) { //清理页面缓存
        alert("你点击："+divId);
    },
    helpDocument: function (divId) { //帮助文档
        alert("你点击："+divId);
    },
    KAcommunity: function (divId) { //KA 社区
        alert("你点击："+divId);
    },
    ApplicationCommunity: function (divId) { //应用
        alert("你点击："+divId);
    },
    kaApp: function (divId) { //KA APP
        kaValue.downloadCtx.down("app");
    },
    pcApp: function(divId){ //PC APP
        kaValue.downloadCtx.down("exe");
    },
    logout: function (popup) {// 注销
        //清除登录缓存
        kaBuss.kaCookieClear();
        //调用
        var option = kaValue.getUrl(kaValue.home.url.logout);
        option.success = function (re) {
            if (re.code == 200) {
                popup.success(kaValue.home.msg.logoutSucees, function () {
                    kaBuss.locationLoginHref();// 跳转登录页面
                })
            }
        }
        ka.ajax(option);
        // 清空 tabs 缓存
        return new Promise((resolve) => {
            resolve(true)
        });
    }
}
